package com.algorithm;

import java.util.Stack;

/**
 * @author: sun.hongliang
 * @create: 2019/12/12 14:53
 */
public class RotateMatrixTest {

    public static void main(String[] args) {

    }

    public void rotate(int[][] matrix) {
        int len = matrix.length;
        for (int i = 0; i < len / 2; i++) {
            for (int j = 0; j < len - 1 - i - i; j++) {
                int temp = matrix[i][i + j];
                matrix[i][i + j] = matrix[len - 1 - i - j][i];
                matrix[len - 1 - i - j][i] = matrix[len - 1 - i][len - 1 - i - j];
                matrix[len - 1 - i][len - 1 - i - j] = matrix[i + j][len - 1 - i];
                matrix[i + j][len - 1 - i] = temp;
            }
        }
    }

    public boolean isValidBST(TreeNode root) {
        if(root == null) return true;
        Stack<TreeNode> stack = new Stack<>();
        stack.push(root);
        Integer min = null;
        while(!stack.isEmpty()){
            while(root.left != null){
                stack.push(root.left);
                root = root.left;
            }
            if(!stack.isEmpty()){
                TreeNode temp = stack.pop();
                if(min == null){
                    min = temp.val;
                }else{
                    if(temp.val <= min){
                        return false;
                    }
                }
                root = temp.right;
            }
        }
        return true;
    }

}
